# -*- coding: utf-8 -*-
'''
Utility module
@undocumented: __package__ logger __ch
'''

import logging, sys
from lxml import etree

# Log levels:
# DEBUG     error_log
# INFO
# WARNING
# ERROR
# CRITICAL

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
__ch = logging.StreamHandler()  # default - stderr => /var/log/httpd/error_log
__ch.setLevel(logging.DEBUG)
logger.addHandler(__ch)
LOG = logger.debug     #: logging function

def pprintxml_s(s):
    '''
    Pretty print xml source.
    TODO: check s.startswith('<?xml')
    @param s: source xml string
    @type s: str
    @return: indented xml
    @rtype: str
    '''
    return etree.tostring(etree.fromstring(s), pretty_print = True)

def pprintxml(e):
    '''
    Pretty print xml source.
    TODO: check s.startswith('<?xml')
    @param e: source xml
    @type e: etree.Element
    @return: indented xml
    @rtype: str
    '''
    return etree.tostring(e, pretty_print = True)
